package com.jinlia.show.modules.wxapp.config;

import com.jinlia.show.modules.base.system.service.OrderMapperService;
import com.jinlia.show.modules.base.utils.OrderNumGenerator;
import com.jinlia.show.modules.base.utils.PayOrderNumGenerator;
import com.jinlia.show.modules.base.wxapp.entity.AppConfig;
import com.jinlia.show.modules.base.wxapp.service.AppConfigMapperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration()
public class BeanConfig {
    /**
     * 商户号
     */
    public static String merchantId = "190000****";

    /**
     * 商户API私钥路径
     */
    public static String privateKeyPath = "/Users/yourname/your/path/apiclient_key.pem";

    /**
     * 商户证书序列号
     */
    public static String merchantSerialNumber = "5157F09EFDC096DE15EBE81A47057A72********";

    /**
     * 商户APIV3密钥
     */
    public static String apiV3Key = "...";
    @Autowired
    AppConfigMapperService appConfigMapperService;

    //    @Bean
//    public JsapiServiceExtension  JsapiServiceExtension(){
//        // 初始化商户配置
//        Config config =
//                new RSAAutoCertificateConfig.Builder()
//                        .merchantId(merchantId)
//                        // 使用 com.wechat.pay.java.core.util 中的函数从本地文件中加载商户私钥，商户私钥会用来生成请求的签名
//                        .privateKeyFromPath(privateKeyPath)
//                        .merchantSerialNumber(merchantSerialNumber)
//                        .apiV3Key(apiV3Key)
//                        .build();
//        // 初始化服务
//        JsapiServiceExtension jsapiServiceExtension = new JsapiServiceExtension.Builder()
//                        .config(config)
//                        .signType("RSA") // 不填默认为RSA
//                        .build();
//        return jsapiServiceExtension;
//    }
    @Bean
    public AppConfig appConfig() {
        AppConfig byId = appConfigMapperService.getById(1l);
        return byId;
    }

    @Bean
    public PayOrderNumGenerator payOrderNumGenerator() {
        PayOrderNumGenerator payOrderNumGenerator = new PayOrderNumGenerator();
        return payOrderNumGenerator;
    }

    @Autowired
    OrderMapperService orderMapperService;
    @Bean
    public OrderNumGenerator orderNumGenerator() {
        OrderNumGenerator orderNumGenerator = new OrderNumGenerator(orderMapperService);
        return orderNumGenerator;
    }
}
